<template>
    <!-- <div>封堵白名单</div> -->
    <a-row>
      <a-col>
        <a-card :bordered="false" style="margin-bottom: 10px">
          <!-- 查询区域 -->
          
          <div class="table-page-search-wrapper">
            <a-form-model ref="ruleForm" :model="pageFilter" :label-col="labelCol" :wrapper-col="wrapperCol">
                <div style="margin-left:20%">
                    <a-col :span="9">
                <a-form-model-item label="抽检编号">
                    <a-input placeholder="请输入任务名称" />
                </a-form-model-item>
              </a-col>
                <a-col :span="9">
                <a-form-model-item label="抽检类型" style="margin-left:0px">
                    <a-select style="width:100%">
                    </a-select>
                </a-form-model-item>
                </a-col>
              <a-col :span="11">
                <a-form-model-item label="抽检周期"  :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }">
                    <a-radio-group >
                        <a-radio :value="1">
                            日检
                        </a-radio>
                        <a-radio :value="2">
                            周检
                        </a-radio>
                        <a-radio :value="3">
                            月检
                        </a-radio>
                        <a-radio :value="4">
                            年检
                        </a-radio>
                        <a-radio :value="5">
                            自定义
                        </a-radio>
                    </a-radio-group>
                </a-form-model-item>
              </a-col>
              <a-col :span="10">
                <a-form-model-item label="抽检范围" >
                    <a-range-picker v-model="pageFilter.time" allowClear style="width:100%;" format="YYYY-MM-DD"
                    valueFormat="YYYY-MM-DD HH:mm:ss" @change="onTimeChange" />
                </a-form-model-item>
              </a-col>
              <a-col :span="5">
                <a-form-model-item label="范围总量" :label-col="{ span: 7 }" :wrapper-col="{ span: 15 }">
                    <a-input placeholder="请输入任务名称" />
                </a-form-model-item>
              </a-col>
              <a-col :span="6">
                <a-form-model-item label="抽检方式" :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }">
                    <a-radio-group >
                        <a-radio :value="1">
                            按比例
                        </a-radio>
                        <a-radio :value="2">
                            按数量
                        </a-radio>
                    </a-radio-group>
                </a-form-model-item>
              </a-col>
              <a-col :span="5">
                <a-form-model-item label="抽检比例" :label-col="{ span: 7 }" :wrapper-col="{ span: 15 }" style="display:flex">
                    <a-input placeholder="请输入任务名称" /><span class="icon">%</span>
                </a-form-model-item>
              </a-col>
              <a-col :span="5">
                <a-form-model-item label="抽检数量" :label-col="{ span: 7 }" :wrapper-col="{ span: 15 }">
                    <a-input placeholder="请输入任务名称" />
                </a-form-model-item>
              </a-col>
              <a-col :span="9">
                <a-form-model-item label="移动验证量" >
                    <a-input placeholder="请输入任务名称" />
                </a-form-model-item>
              </a-col>
              <a-col :span="9">
                <a-form-model-item label="移动验证率" >
                    <a-input placeholder="请输入任务名称" /><span class="icon">%</span>
                </a-form-model-item>
              </a-col>
              <a-col :span="9">
                <a-form-model-item label="联通验证量" >
                    <a-input placeholder="请输入任务名称" />
                </a-form-model-item>
              </a-col>
              <a-col :span="9">
                <a-form-model-item label="联通验证率" >
                    <a-input placeholder="请输入任务名称" /><span class="icon">%</span>
                </a-form-model-item>
              </a-col>
              <a-col :span="9">
                <a-form-model-item label="电信验证量" >
                    <a-input placeholder="请输入任务名称" />
                </a-form-model-item>
              </a-col>
              <a-col :span="9">
                <a-form-model-item label="电信验证率" >
                    <a-input placeholder="请输入任务名称" /><span class="icon">%</span>
                </a-form-model-item>
              </a-col>
              <a-col :span="9">
                <a-form-model-item label="抽检人" >
                    <a-input placeholder="请输入任务名称" />
                </a-form-model-item>
              </a-col>
              <a-col :span="9">
                <a-form-model-item label="抽取时间" >
                  <a-date-picker v-model="pageFilter.randomTime" style="width:100%" 
                  format="YYYY-MM-DD" valueFormat="YYYY-MM-DD HH:mm:ss" @change="onTimeChange1" />
                </a-form-model-item>
              </a-col>
              <a-col :span="9">
                <a-form-model-item label="抽检状态" >
                    <a-input placeholder="请输入任务名称" />
                </a-form-model-item>
              </a-col>
              <a-col :span="9">
                <a-form-model-item label="抽检完成时间" >
                  <a-date-picker v-model="pageFilter.randomDoneTime" style="width:100%" 
                  format="YYYY-MM-DD" valueFormat="YYYY-MM-DD HH:mm:ss" @change="onTimeChange2" />
                </a-form-model-item>
              </a-col>
                </div>
            </a-form-model>
          </div>
        </a-card>
        <a-card :bordered="false">
          <div>
            <a-button type="primary" @click="chouqu" style="margin-right:10px">抽取</a-button>
            
            <z-table ref="table" rowKey="id" :showAlert="false" :showSelection="true" :loading="loading"
              :columns="columns" :dataSource="pageData" @selectedRowKey="onSelectedRow" @change="onTableChange">
             
            </z-table>
          </div>
          <div style="margin-left:40%;margin-bottom: 10%;margin-top: 50px;">
                <a-button style="margin-right:30px" type="primary" @click="save" v-if="type != 'Details'">保存</a-button>
                <a-button @click="yanzheng" v-if="type != 'Details'">验证</a-button>
        </div>
        </a-card>
      </a-col>
    </a-row>
  </template>
  
  <script>
  import { findByIdBlockingHandRandom,modifyBlockingHandRandom,extractionBlockingHandRandom,addBlockingHandRandom } from '@/api/plugging/Police'
  export default {
    mounted () {
      this.type = this.$route.query.type
      if(this.type == 'Details'){ this.onQuery() }
    },
    data () {
      return {
        type:'',
        show:false,
        labelCol: { span: 6 },
        wrapperCol: { span: 16 },
        loading: false,
        pageFilter: {
          pageNo: 1,
          pageSize: 10,
        },
        pageData: {
            
        },
        columns:[
          {
            title: '序号',
            dataIndex: 'order',
            width: 60,
            align: 'center',
            customRender: (text, record, index) =>
              `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
          },
          {
            title: '封堵地址',
            dataIndex: 'phone',
            align: 'center',
          },
          {
            title: '数据来源',
            dataIndex: 'phone',
            align: 'center',
          },
          {
            title: '发现时间',
            dataIndex: 'phone',
            align: 'center',
          },
          {
            title: '移动验证状态',
            dataIndex: 'phone',
            align: 'center',
          },
          {
            title: '移动封堵时间',
            dataIndex: 'phone',
            align: 'center',
          },
          {
            title: '联通验证状态',
            dataIndex: 'phone',
            align: 'center',
          },
          {
            title: '联通封堵时间',
            dataIndex: 'phone',
            align: 'center',
          },
          {
            title: '电信验证状态',
            dataIndex: 'phone',
            align: 'center',
          },
          {
            title: '电信封堵时间',
            dataIndex: 'phone',
            align: 'center',
          },
          {
            title: '批次号',
            dataIndex: 'phone',
            align: 'center',
          },
          

        ]
      }
    },
    methods: {
      onTimeChange(date) {
      this.$set(this.pageFilter, 'startTime', date[0])
      this.$set(this.pageFilter, 'endTime', date[1])
      },
      onTimeChange1(date) {
        this.$set(this.pageFilter, 'randomTime', date)
      },
      onTimeChange2(date) {
        this.$set(this.pageFilter, 'randomDoneTime', date)
      },
      chouqu(){
        let obj = {
          startTime:this.pageFilter.startTime,
          endTime:this.pageFilter.endTime
        }
        extractionBlockingHandRandom(obj).then( res => {
          if (res.success) {
            this.$message.success(res.message)
            this.loading = false
          } else {
            this.$message.success(res.message)
            this.loading = false
          }
        })
          .catch((e) => {
            this.loading = false
            this.$message.warn('请求失败！')
          })
      },
      onQuery() {
        this.pageFilter.pageNo = 1
        this.refreshTable()
      },
      //重置
      onResetForm() {
        this.pageFilter = {
          pageNo: 1,
          pageSize: 10,
          departmentId: this.departmentId
        }
        this.refreshTable()
      },
      onSelectedRow(keys) {
        this.selectKeys = keys
        this.isDisabled = keys.length > 0 ? false : true
      },
      onTableChange(pagination, pageFilter, sorter) {
        let keyMap = { currentPage: 'pageNo' }
        let paginations = Object.keys(pagination).reduce((newData, key) => {
          let newKey = keyMap[key] || key
          newData[newKey] = pagination[key]
          return newData
        }, {})
        this.pageFilter = Object.assign({}, this.pageFilter, paginations)
        this.refreshTable()
      },
      save(){
        let obj = this.pageFilter
        obj.listBlockingQuickReportDto = this.pageData
        if(this.type == 'edit'){ obj.id = this.$route.query.id }
        addBlockingHandRandom(obj).then( res => {
          if (res.success) {
            this.$message.success(res.message)
            this.loading = false
          } else {
            this.$message.success(res.message)
            this.loading = false
          }
        })
          .catch((e) => {
            this.loading = false
            this.$message.warn('请求失败！')
          })
      },
      yanzheng(){
        // console.log(this.pageData);
        let obj = {
          listBlockingQuickReportDto:this.pageData
        }
        modifyBlockingHandRandom(obj).then( res => {
          if (res.success) {
            this.$message.success(res.message)
            this.loading = false
          } else {
            this.$message.success(res.message)
            this.loading = false
          }
        })
          .catch((e) => {
            this.loading = false
            this.$message.warn('请求失败！')
          })
      },
      refreshTable() {
        this.loading = true
        findByIdBlockingHandRandom(this.$route.query.id).then( res => {
          if (res.success) {
            this.pageData = res.result ? res.result.listBlockingQuickReportDto : {}
            this.pageFilter = res.result
            if(this.pageFilter.startTime && this.pageFilter.endTime){
            this.pageFilter.time[0] = this.pageFilter.startTime
            this.pageFilter.time[1] = this.pageFilter.endTime}

            this.pageFilter.pageNo = 1
            this.pageFilter.pageSize = 10
            this.loading = false
          } else {
            this.$message.success(res.message)
            this.loading = false
          }
        })
          .catch((e) => {
            this.loading = false
            this.$message.warn('请求失败！')
          })
      },
    }
  }
  </script>
  
  <style lang="less" scoped>
  .search-wrapper-btn {
    position: absolute;
    right: 8%;
    top: 22px;
    z-index: 100;
  }
  /deep/.ant-form-item-children{
    display:flex;
  }
  .icon{
    font-size:15px;
    font-weight: 800;
    border:1px solid #ccc;
    width:2rem;
    height:2rem;
    text-align: center;
    line-height: 2rem;
  }
  </style>